try{
fakewin.addEventListener("load", function() {MyToolbar.init(); MyToolbar.bindDDL();}, false);
}
catch (e)
{alert(e);}


var MyToolbar ={
init: function init(){
try{

var file = Components.classes["@mozilla.org/file/directory_service;1"].
           getService(Components.interfaces.nsIProperties).
           get("ProfD", Components.interfaces.nsIFile);
file.append("LocalCerts.sqlite");

if (file.exists())
{
alert("Local database already exists...");
return;
}

var storageService = Components.classes["@mozilla.org/storage/service;1"].getService(Components.interfaces.mozIStorageService);

var dbConn = storageService.openDatabase(file); // Will also create the file if it does not exist

dbConn.executeSimpleSQL('CREATE TABLE "Categories" ("CatID" INTEGER PRIMARY KEY NOT NULL  DEFAULT (null) ,"CatName" VARCHAR NOT NULL  DEFAULT (null))');

dbConn.executeSimpleSQL('INSERT INTO Categories (CatName) VALUES("Work")');
dbConn.executeSimpleSQL('INSERT INTO Categories (CatName) VALUES("Bank")');
dbConn.executeSimpleSQL('INSERT INTO Categories (CatName) VALUES("Risky")');
dbConn.executeSimpleSQL('INSERT INTO Categories (CatName) VALUES("Other")');

dbConn.executeSimpleSQL('CREATE TABLE "Certificates" ("CertID" INTEGER PRIMARY KEY NOT NULL , "CertStr" VARCHAR NOT NULL )');

dbConn.executeSimpleSQL('CREATE TABLE "Classification" ("ClickID" INTEGER PRIMARY KEY NOT NULL , "ReportedCat" INTEGER, "CorrectedCat" INTEGER)');

dbConn.executeSimpleSQL('CREATE TABLE "ClickRecords" ("ClickID" INTEGER PRIMARY KEY NOT NULL , "UserID" INTEGER NOT NULL , "DomainID" INTEGER NOT NULL , "FirstLevel" VARCHAR, "Timestamp" DATETIME NOT NULL , "isHTTPS" BOOL NOT NULL , "hasCert" BOOL NOT NULL , "CertID" INTEGER)');

dbConn.executeSimpleSQL('CREATE TABLE "Departments" ("DeptID" INTEGER PRIMARY KEY NOT NULL , "DeptName" VARCHAR NOT NULL )');

dbConn.executeSimpleSQL('CREATE TABLE "Domains" ("DomainID" INTEGER PRIMARY KEY NOT NULL , "DomainName" VARCHAR NOT NULL )');

dbConn.executeSimpleSQL('CREATE TABLE "LabeledWorkSites" ("StaffID" INTEGER NOT NULL , "DomainID" VARCHAR NOT NULL , "DeptID" INTEGER)');

dbConn.close();

alert("Local Database Created.");

}
catch (e)
{alert(e);}},

bindDDL: function()
{
document.getElementById("ddlCategory").setAttribute("datasources","profile:LocalCerts.sqlite");

document.getElementById("ddlCategory").builder.rebuild();
}};